const UserModel = require('../model/UserModel');
const UserService = {
    addUser: (username, password, age, avatar) =>{
        return UserModel.create({
            username,
            password,
            age,
            avatar
        }).then(data=>{
            console.log(data)
        })
    },
    updateUser: (username, password, age, req) =>{
        return UserModel.updateOne({
            _id: req.params.id
        },{
            username, password, age
        }).then(data=>{
            console.log(data)
            
        }) 
    },
    deleteUser: (id) =>{
        return UserModel.deleteOne({
            _id: id
        }).then(data=>{
            console.log(data)
        })
    },
    findUser: (page, limit, res) =>{
        console.log(1322313132)
        return UserModel.find({},["username", "age", "avatar"]).sort({age:1}).skip((page-1)*limit).limit(limit)
    },
    login: (username, password) =>{
        return UserModel.find({
            username,
            password
        })
    }
} 

module.exports = UserService